package org.example.demosr5.controller;

import org.apache.ibatis.annotations.Insert;
import org.example.demosr5.entity.Student;
import org.example.demosr5.mapper.StudentMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class StudentController {
//    @GetMapping(value = "/student/{number}")
//    public Object student(@PathVariable int number) {
//        Student student = new Student();
//        student.setNumber(number);
//        student.setName("张三");
//        return student;
//    }
@Autowired
StudentMapper studentMapper;

    @GetMapping(value = "/students/{number}")
    public Object student(@PathVariable("number") String number) {
        return studentMapper.findByNumber(number);
    }
    @DeleteMapping(value = "/students/{number}")
    public Object student2(@PathVariable("number") String number) {
        return studentMapper.deleteByNumber(number);
    }
    @PostMapping(value = "/students/{number}/{name}")
    public Object student3(@PathVariable("number") String number, @PathVariable("name") String name) {
        return studentMapper.createBynumber(number,name);
    }
    @PutMapping(value = "/students/{number}/{name}")
    public Object student4(@PathVariable("number") String number, @PathVariable("name") String name) {
        return studentMapper.updateByNumber(number,name);
    }
}
